//
//  TableViewController.m
//  ImageView
//
//  Created by Apple on 1/25/16.
//  Copyright © 2016 Apple. All rights reserved.
//

#import "TableViewController.h"
#import "CollectionView.h"
#import "NSString+Ext.h"
#import "CollectionViewCell.h"
@interface TableViewController ()
{
    CollectionView *collection;
    NSMutableArray *array;
    NSNumber * Counts;
}
@end

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UINib *cellNib = [UINib nibWithNibName:@"CollectionView" bundle:nil];
    [self.tableView registerNib:cellNib forCellReuseIdentifier:@"CollectionView"];
    collection=[self.tableView dequeueReusableCellWithIdentifier:@"CollectionView"];
    array=[NSMutableArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],[NSNumber numberWithInt:3],[NSNumber numberWithInt:4],[NSNumber numberWithInt:5],[NSNumber numberWithInt:6],[NSNumber numberWithInt:7],[NSNumber numberWithInt:8] ,[NSNumber numberWithInt:9],[NSNumber numberWithInt:10],[NSNumber numberWithInt:0],nil];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CollectionView *cell = [tableView dequeueReusableCellWithIdentifier:@"CollectionView" forIndexPath:indexPath];
    Counts=[array objectAtIndex:indexPath.row];
    cell.tableView=tableView;
    cell.Number=[array objectAtIndex:indexPath.row];
    [cell.collection reloadData];
    cell.Name.text=@"Wiallims";
    cell.text.text=@"看电视剧离开现场地方给 i 人民放v 吃吧你们，  白色的；例如看美v 吃女厕变成 v地方过分的进口粮食金额可查询 撒查看 v 下了；可旅时代发生的机会比 v 出门， 女厕被打破投入测向，v收到了咖啡大师所发生的";
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGSize size= [@"看电视剧离开现场地方给 i 人民放v 吃吧你们，  白色的；例如看美v 吃女厕变成 v地方过分的进口粮食金额可查询 撒查看 v 下了；可旅时代发生的机会比 v 出门， 女厕被打破投入测向，v收到了咖啡大师所发生的" calculateSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-24-40, CGFLOAT_MAX) font:[UIFont systemFontOfSize:17.0f]];

    NSNumber *number=[array objectAtIndex:indexPath.row];
    if(number.intValue>9){
       
       return size.height+21+8*4+size.width;
    }else if (number.intValue>6){
        return size.height+21+8*4+size.width;
    }else if (number.intValue>3){
        return size.height+21+8*4+size.width*2.0/3.0;
    }else if(number.intValue>0){
       return  size.height+21+8*4+size.width/3.0;
    }else{
        return size.height+21+8*3+8;
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
